package com.zhangji.springcloud.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @Description:
 * @Author: Zhang Ji
 * @Date: 2021/6/23 14:26
 * Created by IntelliJ IDEA.
 */
@Configuration // 该注解相当于spring中的applicationContext.xml
public class ConfigBean {

    // RestTemplate源码中没有自动装配，因此需要@Bean手动注入容器
    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }
    // ZJTODO: 2021/6/25 配置基于负载均衡的RestTemplate，需要引入@LoadBalanced注解

}
